package com.elective.courseselect.controller;

import com.elective.courseselect.entity.CommentingEntity;
import com.elective.courseselect.service.CommentingService;
import com.elective.courseselect.utils.PageUtils;
import com.elective.courseselect.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author lee
 * @email 943204006@qq.ccom
 * @date 2021-09-04 19:23:06
 */
@RestController
@RequestMapping("courseselect/commenting")
public class CommentingController {
    @Autowired
    private CommentingService commentingService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = commentingService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CommentingEntity commenting = commentingService.getById(id);

        return R.ok().put("commenting", commenting);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CommentingEntity commenting){
		commentingService.save(commenting);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CommentingEntity commenting){
		commentingService.updateById(commenting);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		commentingService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    //评论课程
    @PostMapping("/commentsClass")
    @ApiOperation("评论课程")
    public R commentsClass(@RequestBody CommentingEntity commentingEntity){
        return commentingService.commentsClass(commentingEntity);
    }


    /**
     * 审核课程信息修改
     */
    @GetMapping("/searchCourseComment/{courseId}")
    @ApiOperation("查看课程评论")
    public R searchCourseComment(@PathVariable("courseId") Integer courseId){
        return  commentingService.searchCourseComment(courseId);
    }


    /**
     * 审核课程信息修改
     */
    @GetMapping("/delStuCommenting/{courseId}/{stuId}/{commentId}")
    @ApiOperation("删除课程评论")
    public R delStuCommenting(@PathVariable("courseId") Integer courseId,
                              @PathVariable("stuId") Integer stuId,
                              @PathVariable("commentId") Integer[] commentId){
        return  commentingService.delStuCommenting(courseId,stuId,commentId);
    }

}
